package com.car.loan.project.xr.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.Collection;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.car.loan.project.xr.mapper.LoanAlbumMapper;
import com.car.loan.project.xr.domain.LoanAlbum;
import com.car.loan.project.xr.service.ILoanAlbumService;

/**
 * 相册Service业务层处理
 *
 * @author ruoyi
 * @date 2019-11-03
 */
@Service
public class LoanAlbumServiceImpl implements ILoanAlbumService {

    @Autowired
    private LoanAlbumMapper loanAlbumMapper;

    /**
     * 查询相册
     *
     * @param id 相册ID
     * @return 相册
     */
    @Override
    public LoanAlbum selectLoanAlbumById(Long id) {
        return loanAlbumMapper.selectById(id);
    }

    /**
     * 查询相册列表
     *
     * @param loanAlbum 相册
     * @return 相册
     */
    @Override
    public List<LoanAlbum> selectLoanAlbumList(LoanAlbum loanAlbum) {
        QueryWrapper<LoanAlbum> queryWrapper = new QueryWrapper<>(loanAlbum);
        return loanAlbumMapper.selectList(queryWrapper);
    }


    @Override
    public IPage<LoanAlbum> selectPage(IPage<LoanAlbum> page,
        QueryWrapper<LoanAlbum> queryWrapper) {
        return loanAlbumMapper.selectPage(page, queryWrapper);
    }

    /**
     * 新增相册
     *
     * @param loanAlbum 相册
     * @return 结果
     */
    @Override
    public int insertLoanAlbum(LoanAlbum loanAlbum) {

        return loanAlbumMapper.insert(loanAlbum);
    }

    /**
     * 修改相册
     *
     * @param loanAlbum 相册
     * @return 结果
     */
    @Override
    public int updateLoanAlbum(LoanAlbum loanAlbum) {

        return loanAlbumMapper.updateById(loanAlbum);
    }

    /**
     * 删除相册对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLoanAlbumByIds(Collection<Long> ids) {
        return loanAlbumMapper.deleteBatchIds(ids);
    }

    /**
     * 删除相册信息
     *
     * @param id 相册ID
     * @return 结果
     */
    @Override
    public int deleteLoanAlbumById(Long id) {
        return loanAlbumMapper.deleteById(id);
    }

    @Override
    public int deleteLoanAlbumByIdAndType(Long id, Integer type) {
        if (null == id || id <= 0) {
            throw new NullPointerException("请传入删除参数");
        }
        if (null == type || type <= 0) {
            throw new NullPointerException("请传入删除参数");
        }
        LoanAlbum loanAlbum = new LoanAlbum();
        loanAlbum.setId(id);
        loanAlbum.setType(type);
        Wrapper<LoanAlbum> wrapper = new UpdateWrapper<LoanAlbum>();
        loanAlbumMapper.delete(wrapper);
        return 0;
    }


}
